#include <stdio.h>

void itob(int n, char [], int base);

int main()
{
   // freopen("0.in", "r", stdin);
   // freopen("0.out", "w", stdout);

    char s[1000];
    int n, base;

    while(scanf("%d%d", &n, &base) != EOF) {
        itob(n, s, base);
        printf("%s\n", s);
    }

    return 0;
}
/* 请在这里填写答案 */
char ssss[]={"0123456789abcdefghijklmnopqrstuvwxyz"};
void re(char s[],int l)
{
    for(int i=0,n=l>>1;i<n;++i)
    {
        char b=s[l-i-1];
        s[l-i-1]=s[i];
        s[i]=b;
    }    
}
void itob(int n, char s[], int base)
{
    int l=0,f=0;
    if(n<0)s[0]='-',n=-n,f=1,++l;
    while(n)s[l]=ssss[n%base],n/=base,++l;
    s[l]=0;
    re(s+f,l-f);
}